#include "wxstoolbareditor.h"

#include "wxstoolbaritem.h"
#include "../wxsitemresdata.h"
#include "../properties/wxsbitmapiconeditordlg.h"

#include <wx/artprov.h>
#include <wx/bitmap.h>
#include <wx/intl.h>
#include <wx/image.h>
#include <wx/string.h>

const long wxsToolBarEditor::ID_LISTBOX1 = wxNewId();
const long wxsToolBarEditor::ID_RADIOBUTTON1 = wxNewId();
const long wxsToolBarEditor::ID_RADIOBUTTON2 = wxNewId();
const long wxsToolBarEditor::ID_RADIOBUTTON3 = wxNewId();
const long wxsToolBarEditor::ID_RADIOBUTTON4 = wxNewId();
const long wxsToolBarEditor::ID_STATICLINE1 = wxNewId();
const long wxsToolBarEditor::ID_TEXTCTRL4 = wxNewId();
const long wxsToolBarEditor::ID_TEXTCTRL1 = wxNewId();
const long wxsToolBarEditor::ID_BITMAPBUTTON1 = wxNewId();
const long wxsToolBarEditor::ID_BITMAPBUTTON2 = wxNewId();
const long wxsToolBarEditor::ID_TEXTCTRL2 = wxNewId();
const long wxsToolBarEditor::ID_TEXTCTRL3 = wxNewId();
const long wxsToolBarEditor::ID_STATICLINE2 = wxNewId();
const long wxsToolBarEditor::ID_BUTTON3 = wxNewId();
const long wxsToolBarEditor::ID_BUTTON4 = wxNewId();
const long wxsToolBarEditor::ID_BUTTON1 = wxNewId();
const long wxsToolBarEditor::ID_BUTTON2 = wxNewId();

BEGIN_EVENT_TABLE( wxsToolBarEditor, wxPanel )


END_EVENT_TABLE()

wxsToolBarEditor::wxsToolBarEditor( wxWindow* parent, wxsToolBar* ToolBar ):
  m_Selected( 0 ),
  m_ToolBar( ToolBar ),
  m_BlockTextChange( false ),
  m_BlockSelect( false ) {
  wxWindowID id = wxID_ANY;
  wxStaticBoxSizer* StaticBoxSizer2;
  wxButton* Button4;
  wxStaticText* StaticText2;
  wxButton* Button1;
  wxStaticText* StaticText6;
  wxStaticText* StaticText1;
  wxBoxSizer* BoxSizer2;
  wxStaticText* StaticText3;
  wxButton* Button2;
  wxButton* Button3;
  wxGridSizer* GridSizer1;
  wxStaticText* StaticText5;
  wxBoxSizer* BoxSizer1;
  wxStaticBoxSizer* StaticBoxSizer1;
  wxFlexGridSizer* FlexGridSizer1;
  wxBoxSizer* BoxSizer3;
  wxStaticText* StaticText4;
  Create( parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T( "id" ) );
  BoxSizer1 = new wxBoxSizer( wxHORIZONTAL );
  StaticBoxSizer1 = new wxStaticBoxSizer( wxHORIZONTAL, this, _T( "Content" ) );
  m_Content = new wxListBox( this, ID_LISTBOX1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T( "ID_LISTBOX1" ) );
  StaticBoxSizer1->Add( m_Content, 1, wxEXPAND, 4 );
  BoxSizer1->Add( StaticBoxSizer1, 1, wxEXPAND, 4 );
  StaticBoxSizer2 = new wxStaticBoxSizer( wxVERTICAL, this, _T( "Options" ) );
  GridSizer1 = new wxGridSizer( 2, 2, 5, 5 );
  m_TypeNormal = new wxRadioButton( this, ID_RADIOBUTTON1, _T( "Normal" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_RADIOBUTTON1" ) );
  m_TypeNormal->Disable();
  GridSizer1->Add( m_TypeNormal, 1, wxEXPAND, 5 );
  m_TypeSeparator = new wxRadioButton( this, ID_RADIOBUTTON2, _T( "Separator" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_RADIOBUTTON2" ) );
  m_TypeSeparator->Disable();
  GridSizer1->Add( m_TypeSeparator, 1, wxEXPAND, 5 );
  m_TypeRadio = new wxRadioButton( this, ID_RADIOBUTTON3, _T( "Radio" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_RADIOBUTTON3" ) );
  m_TypeRadio->Disable();
  GridSizer1->Add( m_TypeRadio, 1, wxEXPAND, 5 );
  m_TypeCheck = new wxRadioButton( this, ID_RADIOBUTTON4, _T( "Check" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_RADIOBUTTON4" ) );
  m_TypeCheck->Disable();
  GridSizer1->Add( m_TypeCheck, 1, wxEXPAND, 5 );
  StaticBoxSizer2->Add( GridSizer1, 0, wxEXPAND, 5 );
  StaticLine1 = new wxStaticLine( this, ID_STATICLINE1, wxDefaultPosition, wxSize( 10, -1 ), wxLI_HORIZONTAL, _T( "ID_STATICLINE1" ) );
  StaticBoxSizer2->Add( StaticLine1, 0, wxTOP | wxEXPAND, 5 );
  FlexGridSizer1 = new wxFlexGridSizer( 0, 2, 0, 0 );
  FlexGridSizer1->AddGrowableCol( 1 );
  StaticText6 = new wxStaticText( this, wxID_ANY, _T( "Id:" ), wxDefaultPosition, wxDefaultSize, 0, _T( "wxID_ANY" ) );
  FlexGridSizer1->Add( StaticText6, 1, wxALIGN_CENTER_VERTICAL, 5 );
  m_Id = new wxTextCtrl( this, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_TEXTCTRL4" ) );
  FlexGridSizer1->Add( m_Id, 1, wxTOP | wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticText1 = new wxStaticText( this, wxID_ANY, _T( "Label:" ), wxDefaultPosition, wxDefaultSize, 0, _T( "wxID_ANY" ) );
  FlexGridSizer1->Add( StaticText1, 1, wxTOP | wxALIGN_CENTER_VERTICAL, 5 );
  m_Label = new wxTextCtrl( this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_TEXTCTRL1" ) );
  FlexGridSizer1->Add( m_Label, 1, wxTOP | wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticText4 = new wxStaticText( this, wxID_ANY, _T( "Bitmap:" ), wxDefaultPosition, wxDefaultSize, 0, _T( "wxID_ANY" ) );
  FlexGridSizer1->Add( StaticText4, 1, wxTOP | wxALIGN_CENTER_VERTICAL, 5 );
  m_Bitmap = new wxBitmapButton( this, ID_BITMAPBUTTON1, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_OPEN" ) ), wxART_TOOLBAR ), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON1" ) );
  m_Bitmap->SetDefault();
  FlexGridSizer1->Add( m_Bitmap, 1, wxTOP | wxLEFT | wxEXPAND, 5 );
  StaticText5 = new wxStaticText( this, wxID_ANY, _T( "Disabled bitmap:" ), wxDefaultPosition, wxDefaultSize, 0, _T( "wxID_ANY" ) );
  FlexGridSizer1->Add( StaticText5, 1, wxTOP | wxALIGN_CENTER_VERTICAL, 5 );
  m_Bitmap2 = new wxBitmapButton( this, ID_BITMAPBUTTON2, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_OPEN" ) ), wxART_BUTTON ), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON2" ) );
  m_Bitmap2->SetDefault();
  FlexGridSizer1->Add( m_Bitmap2, 1, wxTOP | wxLEFT | wxEXPAND, 5 );
  StaticText2 = new wxStaticText( this, wxID_ANY, _T( "Tooltip:" ), wxDefaultPosition, wxDefaultSize, 0, _T( "wxID_ANY" ) );
  FlexGridSizer1->Add( StaticText2, 1, wxTOP | wxALIGN_CENTER_VERTICAL, 5 );
  m_ToolTip = new wxTextCtrl( this, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_TEXTCTRL2" ) );
  FlexGridSizer1->Add( m_ToolTip, 1, wxTOP | wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticText3 = new wxStaticText( this, wxID_ANY, _T( "Help text:" ), wxDefaultPosition, wxDefaultSize, 0, _T( "wxID_ANY" ) );
  FlexGridSizer1->Add( StaticText3, 1, wxTOP | wxALIGN_CENTER_VERTICAL, 5 );
  m_HelpText = new wxTextCtrl( this, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_TEXTCTRL3" ) );
  FlexGridSizer1->Add( m_HelpText, 1, wxTOP | wxLEFT | wxALIGN_CENTER_VERTICAL, 3 );
  StaticBoxSizer2->Add( FlexGridSizer1, 0, wxTOP | wxEXPAND, 5 );
  StaticLine2 = new wxStaticLine( this, ID_STATICLINE2, wxDefaultPosition, wxSize( 10, -1 ), wxLI_HORIZONTAL, _T( "ID_STATICLINE2" ) );
  StaticBoxSizer2->Add( StaticLine2, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
  Button3 = new wxButton( this, ID_BUTTON3, _T( "^" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_BUTTON3" ) );
  BoxSizer3->Add( Button3, 1, wxALIGN_CENTER_VERTICAL, 5 );
  Button4 = new wxButton( this, ID_BUTTON4, _T( "v" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_BUTTON4" ) );
  BoxSizer3->Add( Button4, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer3, 1, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
  BoxSizer2 = new wxBoxSizer( wxHORIZONTAL );
  Button1 = new wxButton( this, ID_BUTTON1, _T( "New" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_BUTTON1" ) );
  BoxSizer2->Add( Button1, 1, wxALIGN_CENTER_VERTICAL, 5 );
  Button2 = new wxButton( this, ID_BUTTON2, _T( "Delete" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_BUTTON2" ) );
  BoxSizer2->Add( Button2, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer2, 1, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
  BoxSizer1->Add( StaticBoxSizer2, 0, wxLEFT | wxEXPAND, 5 );
  SetSizer( BoxSizer1 );
  BoxSizer1->Fit( this );
  BoxSizer1->SetSizeHints( this );
  Connect( ID_LISTBOX1, wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( wxsToolBarEditor::Onm_ContentSelect ) );
  Connect( ID_RADIOBUTTON1, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( wxsToolBarEditor::OnTypeChanged ) );
  Connect( ID_RADIOBUTTON2, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( wxsToolBarEditor::OnTypeChanged ) );
  Connect( ID_RADIOBUTTON3, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( wxsToolBarEditor::OnTypeChanged ) );
  Connect( ID_RADIOBUTTON4, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( wxsToolBarEditor::OnTypeChanged ) );
  Connect( ID_TEXTCTRL1, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( wxsToolBarEditor::Onm_LabelText ) );
  Connect( ID_BITMAPBUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsToolBarEditor::OnBitmapClick ) );
  Connect( ID_BITMAPBUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsToolBarEditor::OnBitmap2Click ) );
  Connect( ID_BUTTON3, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsToolBarEditor::OnUpClick ) );
  Connect( ID_BUTTON4, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsToolBarEditor::OnDownClick ) );
  Connect( ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsToolBarEditor::OnNewClick ) );
  Connect( ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsToolBarEditor::OnDelClick ) );
  for( int i = 0; i < m_ToolBar->GetChildCount(); i++ ) {
    wxsItem* Child = m_ToolBar->GetChild( i );
    if( Child->GetClassName() == _T( "wxToolBarToolBase" ) ) {
      wxsToolBarItem* Item = ( wxsToolBarItem* )Child;
      ToolBarItem* New = new ToolBarItem;
      New->m_OriginalPos = -1;
      New->m_Id = Item->GetIdName();
      New->m_Variable = Item->GetVarName();
      New->m_Label = Item->m_Label;
      New->m_Bitmap = Item->m_Bitmap;
      New->m_Bitmap2 = Item->m_Bitmap2;
      New->m_ToolTip = Item->m_ToolTip;
      New->m_HelpText = Item->m_HelpText;
      wxsEvents& Events = Item->GetEvents();
      if( Events.GetCount() > 0 ) {
        New->m_Handler1 = Events.GetHandler( 0 );
      }
      if( Events.GetCount() > 1 ) {
        New->m_Handler2 = Events.GetHandler( 1 );
      }
      switch( Item->m_Type ) {
        case wxsToolBarItem::Radio:
          New->m_Type = Radio;
          break;
        case wxsToolBarItem::Check:
          New->m_Type = Check;
          break;
        case wxsToolBarItem::Separator:
          New->m_Type = Separator;
          New->m_Id = _T( "" );
          break;
        case wxsToolBarItem::Normal:
        default:
          New->m_Type = Normal;
          break;
      }
      m_Content->Append( GetItemLabel( New ), New );
    } else {
      ToolBarItem* New = new ToolBarItem;
      New->m_OriginalPos = i;
      New->m_Label = Child->GetClassName();
      if( Child->GetPropertiesFlags() & flVariable ) {
        New->m_Label << _T( ": " ) << Child->GetVarName();
      }
      New->m_Type = Control;
      m_Content->Append( GetItemLabel( New ), New );
    }
  }
  if( m_Content->GetCount() == 0 ) {
    SelectItem( 0 );
  } else {
    m_Content->Select( 0 );
    SelectItem( ( ToolBarItem* )m_Content->GetClientObject( 0 ) );
  }
}

wxsToolBarEditor::~wxsToolBarEditor() {
}

void wxsToolBarEditor::OnTypeChanged( M_Code_unused wxCommandEvent& event ) {
  ToolBarItem* Selected = m_Selected;
  SelectItem( 0 );
  SelectItem( Selected );
}

namespace {
  typedef wxsItem* wxsItemP;
}

void wxsToolBarEditor::ApplyChanges() {
  SelectItem( m_Selected );
  m_ToolBar->GetResourceData()->BeginChange();
  int NewCount = m_Content->GetCount();
  if( NewCount == 0 ) {
    for( int i = m_ToolBar->GetChildCount(); i-- > 0; ) {
      wxsItem* Child = m_ToolBar->GetChild( i );
      m_ToolBar->UnbindChild( i );
      delete Child;
    }
  }
  wxsItemP* NewChildrenArray = new wxsItemP[NewCount];
  wxArrayBool ParentChildrenUsed;
  ParentChildrenUsed.Add( false, m_ToolBar->GetChildCount() );
  for( int i = 0; i < NewCount; i++ ) {
    ToolBarItem* Item = ( ToolBarItem* )m_Content->GetClientObject( i );
    if( Item->m_Type == Control ) {
      int Index = Item->m_OriginalPos;
      wxASSERT( ParentChildrenUsed[Index] == false );
      NewChildrenArray[i] = m_ToolBar->GetChild( Index );
      ParentChildrenUsed[Index] = true;
    } else {
      wxsToolBarItem* New = new wxsToolBarItem( m_ToolBar->GetResourceData(), Item->m_Type == Separator );
      switch( Item->m_Type ) {
        case Separator:
          New->m_Type = wxsToolBarItem::Separator;
          break;
        case Radio:
          New->m_Type = wxsToolBarItem::Radio;
          break;
        case Check:
          New->m_Type = wxsToolBarItem::Check;
          break;
        case Normal:
        case Control:
        default:
          New->m_Type = wxsToolBarItem::Normal;
          break;
      }
      if( Item->m_Type != Separator ) {
        New->SetIdName( Item->m_Id );
        New->SetVarName( Item->m_Variable );
        New->m_Label = Item->m_Label;
        New->m_Bitmap = Item->m_Bitmap;
        New->m_Bitmap2 = Item->m_Bitmap2;
        New->m_ToolTip = Item->m_ToolTip;
        New->m_HelpText = Item->m_HelpText;
        wxsEvents& Events = New->GetEvents();
        if( Events.GetCount() > 0 ) {
          Events.SetHandler( 0, Item->m_Handler1 );
        }
        if( Events.GetCount() > 1 ) {
          Events.SetHandler( 1, Item->m_Handler2 );
        }
      }
      NewChildrenArray[i] = New;
    }
  }
  for( int i = m_ToolBar->GetChildCount(); i-- > 0; ) {
    wxsItem* Child = m_ToolBar->GetChild( i );
    m_ToolBar->UnbindChild( Child );
    if( !ParentChildrenUsed[i] ) {
      delete Child;
    }
  }
  for( int i = 0; i < NewCount; i++ ) {
    if( !m_ToolBar->AddChild( NewChildrenArray[i] ) ) {
      delete NewChildrenArray[i];
    }
  }
  delete[] NewChildrenArray;
  m_ToolBar->GetResourceData()->EndChange();
}

wxString wxsToolBarEditor::GetItemLabel( ToolBarItem* Item ) {
  if( Item->m_Type == Separator ) {
    return _T( "--------" );
  }
  return Item->m_Label;
}


void wxsToolBarEditor::Onm_ContentSelect( M_Code_unused wxCommandEvent& event ) {
  if( m_BlockSelect ) {
    return;
  }
  int Selection = m_Content->GetSelection();
  if( Selection == wxNOT_FOUND ) {
    SelectItem( 0 );
  } else {
    SelectItem( ( ToolBarItem* )m_Content->GetClientObject( Selection ) );
  }
}


void wxsToolBarEditor::Onm_LabelText( M_Code_unused wxCommandEvent& event ) {
  if( m_BlockTextChange ) {
    return;
  }
  m_BlockSelect = true;
  if( m_Selected ) {
    m_Selected->m_Label = m_Label->GetValue();
    int Selection = m_Content->GetSelection();
    m_Content->SetString( Selection, GetItemLabel( m_Selected ) );
    m_Content->SetSelection( Selection );
  }
  m_BlockSelect = false;
}

void wxsToolBarEditor::SelectItem( ToolBarItem* Item ) {
  m_BlockTextChange = true;
  if( m_Selected != 0 ) {
    if( m_Selected->m_Type != Control ) {
      m_Selected->m_Type = Normal;
      if( m_TypeCheck->GetValue() ) {
        m_Selected->m_Type = Check;
      }
      if( m_TypeRadio->GetValue() ) {
        m_Selected->m_Type = Radio;
      }
      if( m_TypeSeparator->GetValue() ) {
        m_Selected->m_Type = Separator;
      }
      m_Selected->m_Id = m_Id->GetValue();
      m_Selected->m_Label = m_Label->GetValue();
      m_Selected->m_ToolTip = m_ToolTip->GetValue();
      m_Selected->m_HelpText = m_HelpText->GetValue();
    }
  }
  if( m_Selected == Item ) {
    m_BlockTextChange = false;
    return;
  }
  m_Selected = Item;
  if( m_Selected ) {
    if( m_Selected->m_Type == Control ) {
      m_TypeNormal->Disable();
      m_TypeNormal->SetValue( false );
      m_TypeCheck->Disable();
      m_TypeCheck->SetValue( false );
      m_TypeRadio->Disable();
      m_TypeRadio->SetValue( false );
      m_TypeSeparator->Disable();
      m_TypeSeparator->SetValue( false );
      m_Id->Disable();
      m_Id->SetValue( _T( "" ) );
      m_Label->Disable();
      m_Label->SetValue( _T( "" ) );
      m_Bitmap->Disable();
      m_Bitmap->SetBitmapLabel( wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_OPEN" ) ), wxART_TOOLBAR ) );
      m_Bitmap2->Disable();
      m_Bitmap2->SetBitmapLabel( wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_OPEN" ) ), wxART_TOOLBAR ) );
      m_ToolTip->Disable();
      m_ToolTip->SetValue( _T( "" ) );
      m_HelpText->Disable();
      m_HelpText->SetValue( _T( "" ) );
    } else {
      bool IsSeparator = m_Selected->m_Type == Separator;
      m_TypeNormal->Enable();
      m_TypeNormal->SetValue( m_Selected->m_Type == Normal );
      m_TypeCheck->Enable();
      m_TypeCheck->SetValue( m_Selected->m_Type == Check );
      m_TypeRadio->Enable();
      m_TypeRadio->SetValue( m_Selected->m_Type == Radio );
      m_TypeSeparator->Enable();
      m_TypeSeparator->SetValue( m_Selected->m_Type == Separator );
      m_Id->Enable( !IsSeparator );
      m_Id->SetValue( m_Selected->m_Id );
      m_Label->Enable( !IsSeparator );
      m_Label->SetValue( m_Selected->m_Label );
      m_Bitmap->Enable( !IsSeparator );
      if( m_Selected->m_Bitmap.IsEmpty() || !m_Selected->m_Bitmap.CodeText.IsEmpty() ) {
        m_Bitmap->SetBitmapLabel( wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_OPEN" ) ), wxART_TOOLBAR ) );
      } else
      { m_Bitmap->SetBitmapLabel( m_Selected->m_Bitmap.GetPreview( wxDefaultSize, _T( "wxART_TOOLBAR" ) ) ); }
      m_Bitmap2->Enable( !IsSeparator );
      if( m_Selected->m_Bitmap2.IsEmpty() ) {
        m_Bitmap2->SetBitmapLabel( wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_OPEN" ) ), wxART_TOOLBAR ) );
      } else
      { m_Bitmap2->SetBitmapLabel( m_Selected->m_Bitmap2.GetPreview( wxDefaultSize, _T( "wxART_TOOLBAR" ) ) ); }
      m_ToolTip->Enable( !IsSeparator );
      m_ToolTip->SetValue( m_Selected->m_ToolTip );
      m_HelpText->Enable( !IsSeparator );
      m_HelpText->SetValue( m_Selected->m_HelpText );
    }
  }
  m_BlockTextChange = false;
}

void wxsToolBarEditor::OnUpClick( M_Code_unused wxCommandEvent& event ) {
  if( !m_Selected ) {
    return;
  }
  SelectItem( m_Selected );
  int SelIndex = m_Content->GetSelection();
  if( SelIndex == wxNOT_FOUND ) {
    return;
  }
  if( SelIndex == 0 ) {
    return;
  }
  ToolBarItem* Copy = new ToolBarItem( *( ( ToolBarItem* )m_Content->GetClientObject( SelIndex - 1 ) ) );
  m_Content->Delete( SelIndex - 1 );
  m_Content->Insert( GetItemLabel( Copy ), SelIndex, Copy );
}

void wxsToolBarEditor::OnDownClick( M_Code_unused wxCommandEvent& event ) {
  if( !m_Selected ) {
    return;
  }
  SelectItem( m_Selected );
  int SelIndex = m_Content->GetSelection();
  if( SelIndex == wxNOT_FOUND ) {
    return;
  }
  if( SelIndex > ( int )m_Content->GetCount() - 2 ) {
    return;
  }
  ToolBarItem* Copy = new ToolBarItem( *( ( ToolBarItem* )m_Content->GetClientObject( SelIndex + 1 ) ) );
  m_Content->Delete( SelIndex + 1 );
  m_Content->Insert( GetItemLabel( Copy ), SelIndex, Copy );
}

void wxsToolBarEditor::OnNewClick( M_Code_unused wxCommandEvent& event ) {
  SelectItem( m_Selected );
  ToolBarItem* New = new ToolBarItem();
  New->m_Label = _T( "New item" );
  int SelIndex = m_Content->GetSelection();
  if( SelIndex == wxNOT_FOUND ) {
    m_Content->SetSelection( m_Content->Append( GetItemLabel( New ), New ) );
  } else {
    m_Content->Insert( GetItemLabel( New ), SelIndex + 1, New );
    m_Content->SetSelection( SelIndex + 1 );
  }
  SelectItem( New );
}

void wxsToolBarEditor::OnDelClick( M_Code_unused wxCommandEvent& event ) {
  int Selection = m_Content->GetSelection();
  if( Selection == wxNOT_FOUND ) {
    return;
  }
  if( msging( _T( "Are you sure to delete this item?" ),
              _T( "Deleting wxToolBar item" ),
              wxYES_NO ) == wxID_YES ) {
    m_Content->Delete( Selection );
    if( ( int )m_Content->GetCount() == Selection ) {
      Selection--;
    }
    if( Selection > 0 ) {
      m_Content->SetSelection( Selection );
      SelectItem( ( ToolBarItem* )m_Content->GetClientObject( Selection ) );
    } else {
      m_Content->SetSelection( wxNOT_FOUND );
      SelectItem( 0 );
    }
  }
}

void wxsToolBarEditor::OnBitmapClick( M_Code_unused wxCommandEvent& event ) {
  if( !m_Selected ) {
    return;
  }
  ToolBarItem* Selected = m_Selected;
  SelectItem( Selected );
  wxsBitmapIconEditorDlg Dlg( this, Selected->m_Bitmap, _T( "wxART_TOOLBAR" ) );
  Dlg.ShowModal();
  SelectItem( 0 );
  SelectItem( Selected );
}


void wxsToolBarEditor::OnBitmap2Click( M_Code_unused wxCommandEvent& event ) {
  if( !m_Selected ) {
    return;
  }
  ToolBarItem* Selected = m_Selected;
  SelectItem( Selected );
  wxsBitmapIconEditorDlg Dlg( this, Selected->m_Bitmap2, _T( "wxART_TOOLBAR" ) );
  Dlg.ShowModal();
  SelectItem( 0 );
  SelectItem( Selected );
}
